package redis

import (
	"context"
	"fmt"
)

// SyncGoodsStock 添加库存
func SyncGoodsStock(goodsId int, goodsStock int) {
	key := fmt.Sprintf("goods_stock:goods_id_%d", goodsId)
	for i := 0; i < goodsStock; i++ {
		Rdb.RPush(context.Background(), key, goodsId)
	}
}

// GetGoodsStock 查询库存
func GetGoodsStock(goodsId int) int64 {
	key := fmt.Sprintf("goods_stock:goods_id_%d", goodsId)
	return Rdb.LLen(context.Background(), key).Val()
}
